/* MAKE ARRAY
 * Converts any given file into a C array
 *
 * Sean Middleditch <sean@mojodo.com>
 * DEDICATED TO THE PUBLIC DOMAIN - September, 2008
 */

#include <stdio.h>
#include <string.h>
#include <errno.h>

int main (int argc, char **argv)
{
	const char* name = "file";
	size_t size = 0;
	int byte;

	/* get name */
	if (argc > 1)
		name = argv[1];

	/* output header */
	printf("const char %s[] = {\n ", name);

	/* read in bytes, and spit them out */
	while ((byte = fgetc(stdin)) != EOF) {
		printf(" '\\x%02x',", byte);
		if (++size % 9 == 0)
			printf("\n ");
	}

	/* output footer */
	printf(" '\\0'\n};\nconst unsigned int %s_len = %lu;\n", name, size);
	return 0;
}
